package cms_article

import (
	category "gitee.com/binny_w/gin_starter/model/cms_category"
	util2 "gitee.com/binny_w/go-util/v2"
	"github.com/gin-gonic/gin"
)

func infoFixer(c *gin.Context, row *util2.MysqlRow) error {
	tags := row.ToStrings("tags")
	row.Set("tags", tags)
	cover := gin.H{
		"bucket": "",
		"key":    "",
	}
	covers := row.ToStrings("cover")
	if len(covers) >= 2 {
		cover["bucket"] = covers[0]
		cover["key"] = covers[1]
	}
	row.Set("cover", cover)
	if tree, err := category.Tree(c); err == nil {
		if _, ok := tree.ItemByKey(row.ToStr("category_key")); !ok {
			row.Set("category_key", "")
		}
	}
	return nil
}
